* Set the working directory to the main one of the project

use model\dsets_for_model\patents_data\dataset_for_gravity_knowflow.dta, clear

ppmlhdfe share_cit_ns_mr migrational_exposure same_cz distance if tot_cit_ns != ., absorb(cz_macroipc_citing_id cz_macroipc_cited_id macroipc_citing_cited_id, savefe) cluster(cz_macroipc_citing_id)

/*
HDFE PPML regression                              No. of obs      =   27527528
Absorbing 3 HDFE groups                           Residual df     =      5,187
Statistics robust to heteroskedasticity           Wald chi2(3)    =  145276.12
Deviance             =   15109.8827               Prob > chi2     =     0.0000
Log pseudolikelihood = -26737.12922               Pseudo R2       =     0.4349

Number of clusters (cz_macroipc_citing_id)=     5,188
                      (Std. Err. adjusted for 5,188 clusters in cz_macroipc_citing_id)
--------------------------------------------------------------------------------------
                     |               Robust
     share_cit_ns_mr |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
---------------------+----------------------------------------------------------------
migrational_exposure |    3.33587   .0771578    43.23   0.000     3.184644    3.487097
             same_cz |   6.426134   .0189142   339.75   0.000     6.389063    6.463205
            distance |  -.0001645   8.67e-06   -18.96   0.000    -.0001814   -.0001475
               _cons |  -7.167072   .0125823  -569.62   0.000    -7.191733   -7.142411
--------------------------------------------------------------------------------------
*/

keep macroipc_citing macroipc_cited __hdfe3__
keep if __hdfe3__ != .
rename __hdfe3__ macroipc_citing_cited_fe
duplicates drop
sort macroipc_citing macroipc_cited 
gen aaa = macroipc_cited
drop macroipc_cited
order aaa, first
rename aaa macroipc_cited

export delimited using model\dsets_for_model\macroipc_citing_cited_fe_cpp.csv, replace novarnames

